<!DOCTYPE html>
<html lang="en">
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title>合伙人加盟</title>
<script src="<%=basePath%>weixin/js/mui.min.js"></script>
<script src="<%=basePath%>weixin/js/jquery.min.js"></script>
<link rel="stylesheet" href="<%=basePath%>weixin/css/mui.min.css" />
<link rel="stylesheet" href="<%=basePath%>weixin/css/order.css" />
<link rel="stylesheet" href="<%=basePath%>weixin/css/base.css" />
<link rel="stylesheet" href="<%=basePath%>weixin/css/style.css" />
<script src="<%=basePath%>weixin/js/mui.picker.min.js"></script>
<script src="<%=basePath%>weixin/js/page/valid.js"></script>
<script src="<%=basePath%>weixin/js/area.js" ></script>
<script src="<%=basePath%>weixin/module/layer_pc/layer.js"></script>
<script src="<%=basePath%>weixin/js/page/common.js"></script>
<style>
	.recommend{margin:15px 0 0 0; background: #fff; border-radius: 5px; padding: 20px; color: #878787;}
</style>
</head>
<body class="bg-f5">
	<div class="flow-chart clearfix">
		<div class="process">
			<span>1</span>
			<p>用户注册</p>
		</div>
		<div class="process">
			<span>2</span>
			<p>支付定金</p>
		</div>
		<div class="process">
			<span>3</span>
			<p>等待审核</p>
		</div>
	</div>
	<div class="container-box" id="steps1">
		<div class="input-group bg-white m-top-30">
			<input type="hidden" id="sid" name="sid" value="${serviceInfo.sid}" />
			<div class="input-group-item">
				<div class="input-group-icon"><i class="login-i login-i-1"></i></div>
				<div class="input-group-text must">
					<input type="text" name="readname" id="readname" maxlength="8" value="${serviceInfo.nickname}" placeholder="真实姓名">
				</div>
			</div>
			<div class="input-group-item">
				<div class="input-group-icon"><i class="login-i login-i-2"></i></div>
				<div class="input-group-text must">
					<input type="text" name="tel" id="tel" placeholder="手机号" value="${serviceInfo.tel}" maxlength="11">
				</div>
				<div class="input-group-text codeInput">
					获取验证码
				</div>
			</div>
			<div class="input-group-item">
				<div class="input-group-icon"><i class="login-i login-i-2"></i></div>
				<div class="input-group-text must">
					<input type="text" id="code" name="code" placeholder="验证码">
				</div>
			</div>
			<div class="input-group-item">
				<div class="input-group-icon"><i class="login-i login-i-3"></i></div>
				<div class="input-group-text must">
					<c:if test="${not empty serviceInfo.province_name }">
						<input type="text" readonly="readonly" id="address1" placeholder="所在地区"
							   value="${serviceInfo.province_name} ${serviceInfo.city_name} ${serviceInfo.area_name}" >
						<input type="text" readonly="readonly" value="${serviceInfo.town_name}" id="address3" placeholder="所在镇/乡/街道">
					</c:if>
					<c:if test="${empty serviceInfo.province_name }">
						<input type="text" readonly="readonly" id="address1" placeholder="所在地区" >
						<input type="text" readonly="readonly" id="address3" placeholder="所在镇/乡/街道">
					</c:if>
					<input type="text" id="address2" name="address" placeholder="店铺地址" value="${serviceInfo.address}" maxlength="50">
					<input type="hidden" id="provinceCode" value="${serviceInfo.province}" />
					<input type="hidden" id="cityCode" value="${serviceInfo.city}"  />
					<input type="hidden" id="areaCode" value="${serviceInfo.area}"  />
					<input type="hidden" id="townCode" value="${serviceInfo.town}"  />
				</div>
			</div>
			<div class="input-group-item">
				<div class="input-group-icon"><i class="login-i login-i-1"></i></div>
				<div class="input-group-text must">
					<input type="text" name="level" id="level" readonly="readonly" placeholder="服务商等级"
						  	<c:if test="${serviceInfo.level==1}">value="省级/直辖市"</c:if>
						  	<c:if test="${serviceInfo.level==2}">value="市级"</c:if>
						  	<c:if test="${serviceInfo.level==3}">value="区/县"</c:if>
						  	<%--<c:if test="${serviceInfo.level==4}">value="镇/乡/街道"</c:if>--%>
					/>
					<input type="hidden" id="levelCode" value="${serviceInfo.level}"  />
				</div>
			</div>
		</div>
		<div class="recommend" style="margin-top:15px;">
			<div class="r-title">
				是否有推荐人
			</div>
			<div class="recommendBtn">
				<div btn="true"><input type="radio" name="btn" value="true" <c:if test="${promotion != null }">checked</c:if> />有</div>
				<div btn="false"><input type="radio" name="btn" value="false" <c:if test="${promotion == null}">checked</c:if> />无</div>
			</div>
			<div class="r-centent  <c:if test="${promotion == null}">hide</c:if> ">
				<div>推荐码：<input type="text" style="width:110px;" onblur="ajaxWxPromotionrInfo()" value="${promotion.code}" id ="promotion_code_a" name="promotion_code" /></div>
				<div>推荐人姓名：<span id="in_service_name"><c:if test="${promotion.userType == '5'}">${promotion.serviceName}</c:if></span></div>
				<div>推荐人手机：<span id="in_service_tel"><c:if test="${promotion.userType == '5'}">${promotion.serviceTel}</c:if></span></div>
			</div>
			<%--<div class="r-centent hide">--%>
				<%--<div>--%>
					<%--推荐服务商：平台服务商--%>
				<%--</div>--%>
			<%--</div>--%>
		</div>
		<a class="m-btn m-btn-block m-top-30 m-bottom-30" steps="1">下一步</a>
	</div>
	<div class="container-box m-top-30 hide" id="steps2">
		<div class="m-top-30">&nbsp;</div>
		<div class="submit-tip">
			<div class="submit-tip-1">提交成功</div>
			<div class="submit-tip-2">请支付定金</div>
		</div>
		<%--<a href="javascript:void(0)" onclick="WeixinJSBridge.call('closeWindow');" class="m-btn m-btn-block m-top-30">完成</a>--%>
		<c:choose>
			<c:when test="${ ( serviceInfo.audit_flag== '0' || serviceInfo.audit_flag== '1' || empty serviceInfo ) && ( payCount < 1  || empty payCount )}">
				<a href="javascript:void(0)" onclick ="serviceBargainPay();" class="m-btn m-btn-block m-top-30">我要付款</a>
			</c:when>
			<c:otherwise>
				<a href="javascript:void(0)" onclick="wxPayHistory();" class="m-btn m-btn-block m-top-30">查看</a>
			</c:otherwise>
		</c:choose>
	</div>
	<script>
		var basePathUrl = "<%=basePath%>";
		var auditflag = "${serviceInfo.audit_flag}";
		var promotionCode = "${promotion.code}";
		var promotionUserType = "${promotion.userType}";
		var payCount = "${payCount}";
		var isInitializeTown = true;//初始化
		//$(function(){
			if(auditflag=='0' || auditflag=='1'){
				document.querySelector('#steps1').classList.add('hide');
				document.querySelector('#steps2').classList.remove('hide');
				document.querySelectorAll('.flow-chart .process')[0].classList.add('active');
				if(payCount>0){
					document.querySelectorAll('.flow-chart .process')[1].classList.add('active');
					document.querySelector('.submit-tip-2').innerHTML = "已支付定金";
				}else{
					document.querySelector('.submit-tip-2').innerHTML = "未支付定金";
				}
				$('.active span').html('&nbsp;');
				document.querySelector('.submit-tip-1').innerHTML = "平台审核中";
			}else{
				if(promotionCode!=null && promotionCode!=''){
					if(promotionUserType=='1'){
						mui.toast("无效的推广码,该推广码为维修店",'da',3500);
					}
				}
			}

		//});
		var apiWxServiceSave = function(data,elementBox,process,index){
			$.ajax({
				type:"post",
				url:"<%=basePath%>api/wx/service/save",
				data : data,
				success : function(data){
					if(data.code==1){
						elementBox.window1.classList.add('hide');
						elementBox.window2.classList.remove('hide');
						process[0].classList.add('active');
						$('.active span').html('&nbsp;');
					} else {
						mui.toast(data.mem);
					}
					layer.close(index);
				}
			});
		};

		if(auditflag != '0' && auditflag != '1'){
			(function(mui){
				mui.init();
				common.init('register-1');
				if(auditflag=='-2' || auditflag=='-1'){
					var auditDescribe = "${serviceInfo.audit_describe}";
					setTimeout(function() {
						mui.toast("平台审核未通过<br>原因:"+auditDescribe,'da',3500);
					}, 800);
				}
			})(mui);
		}
		var telIsRegistered = false;
		var ajaxWxVerifyTel = function (tel,userType,callback,index){
			var user_id = "${serviceInfo.sid}";
			$.ajax({
				type:"POST",
				url:basePathUrl+"ajax/wx/verify/tel",
				data:{
					'user_id' : user_id,
					'tel' : tel,
					'userType' : userType,
					'tm':new Date().getTime()
				},
				dataType:'json',
				cache: false,
				async:false,
				success: function(data){
					if(data.code==1){
						telIsRegistered =  true;
					}else{
						telIsRegistered = false;
					}
					callback(telIsRegistered,index);
				}, error: function(XMLHttpRequest, textStatus, errorThrown) {
					mui.toast(XMLHttpRequest.status+" | "+XMLHttpRequest.readyState+"|"+textStatus);
				}
			});
		};

		function ajaxWxPromotionrInfo(){
			var index = layer.load(2,{shade: [0.2, '#393D49']});
			var promotionCode = $("#promotion_code_a").val();
			$("#in_service_name").html("");
			$("#in_service_tel").html("");
			if(promotionCode.length != 12 && promotionCode.length != 11){
				mui.toast("无效的推广码",'da',3500);
				layer.close(index);
				return ;
			}
			$.ajax({
				type:"POST",
				url:"<%=basePath%>api/wx/promotion/info",
				data:{
					'promotionCode' : promotionCode,
					'tm':new Date().getTime()
				},
				dataType:'json',
				cache: false,
				success: function(data){
					if(data.code==1){
						var jsonArr = eval("("+data.data+")");
						if(jsonArr.userType=='5'){
							$("#in_service_name").html(jsonArr.serviceName);
							$("#in_service_tel").html(jsonArr.serviceTel);
						}else{
							mui.toast("无效的推广码,该推广码为维修店",'da',3500);
						}
					}else{
						mui.toast("无效的推广码",'da',3500);
					}
					layer.close(index);
				}, error: function(XMLHttpRequest, textStatus, errorThrown) {
					// alert(XMLHttpRequest.status+" | "+XMLHttpRequest.readyState+"|"+textStatus);
					mui.toast("Error:请联系管理员!",'da',3500);
				}
			});
		}

		function serviceBargainPay(){
 			window.location.href = "<%=basePath%>api/wx/service/bargain/pay";
		}

		function wxPayHistory(){
			window.location.href="<%=basePath%>api/wx/pay/history?user_id=${serviceInfo.sid}&pay_type=bargain"
		}
	</script>
</body>
</html>